package yuejian_07.yuejian_07.model;

import java.util.List;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;
import yuejian_07.yuejian_07.RetrofitListener;
import yuejian_07.yuejian_07.base.RetrofitListenerThree;
import yuejian_07.yuejian_07.base.RetrofitListenerTow;
import yuejian_07.yuejian_07.javabean.Show;
import yuejian_07.yuejian_07.service.ShowService;

/**
 * Created by dell on 2017/10/16.
 */

public class ShowModel {
    private Retrofit retrofit;
    public ShowModel(){
        retrofit=new Retrofit.Builder()
                .baseUrl("http://10.0.2.2/neu1_yuejian/index.php/Api/")
                .addConverterFactory(GsonConverterFactory.create())
                .build();
    }
    public Call showlist(){
        ShowService showService=retrofit.create(ShowService.class);
        return  showService.getAllShows();

    }
    //获取晒图详情
    public void getShowById(int Show_id, final RetrofitListener listener){
        ShowService showService=retrofit.create(ShowService.class);
        Call call=showService.getShowById(Show_id);
        Callback<Show> callback=new Callback<Show>(){
            @Override
            public void onResponse(Call<Show> call, Response<Show> response){

                listener.onSuccess(response.body());
            }
            @Override
            public void onFailure(Call<Show> call,Throwable t){
                t.printStackTrace();
                listener.onFail();
            }
        };
        call.enqueue(callback);
    }

    /*获取晒图列表根据用户*/
    public void getShowByUser(int User_id, final RetrofitListenerTow listener){
        ShowService showService=retrofit.create(ShowService.class);
        Call call=showService.getShowByUId(User_id);
        Callback<List<Show>> callback=new Callback<List<Show>>(){
            @Override
            public void onResponse(Call<List<Show>> call, Response<List<Show>> response ){
                List<Show> data=response.body();
                listener.onSuccessTow(data);//userId这里有问题
            }
            @Override
            public  void onFailure(Call<List<Show>> call, Throwable t){
                listener.onFailTow();
            }
        };
        call.enqueue(callback);
    }

    /*获取晒图列表根据俱乐部*/
    public void getShowByClub(int Club_id, final RetrofitListenerThree listener){
        ShowService showService=retrofit.create(ShowService.class);
        Call call=showService.getShowByClub(Club_id);
        Callback<List<Show>> callback=new Callback<List<Show>>(){
            @Override
            public void onResponse(Call<List<Show>> call, Response<List<Show>> response ){
                List<Show> data=response.body();
                listener.onSuccessThree(data);
            }
            @Override
            public  void onFailure(Call<List<Show>> call, Throwable t){
                listener.onFailThree();
            }
        };
        call.enqueue(callback);
    }
}
